<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$labels=pdo_getall('jy_yiliao_label',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
$return['labels']=array();
foreach($labels as $lv){
	$return['labels'][$lv['id']]=$lv['title'];
}
if($_RQ['op']=='edit'){
	$item=$worker;
	unset($item['password']);
	$item['years']=date('Y-m-d',$item['years']);
	$item['off_timebox']=$item['off_timebox']?json_decode($item['off_timebox'],true):array(array('times'=>array('start'=>'12:00','end'=>'13:00')));
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'headimg','title'=>'头像','type'=>'image'),
					array('name'=>'name','title'=>'姓名','type'=>'string'),
					array('name'=>'username','title'=>'用户名','type'=>'string'),
					array('name'=>'password','title'=>'密码','type'=>'password'),
					array('name'=>'mobile','title'=>'手机号','type'=>'string'),
					array('name'=>'tel','title'=>'固定电话','type'=>'string'),
					array('name'=>'wechat','title'=>'微信号','type'=>'string'),
					array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
					array('name'=>'years','title'=>'出生年月','type'=>'time'),
					array('name'=>'storeid','title'=>'所属医院','type'=>'select','options'=>'stores'),
					array('name'=>'lesson_id','title'=>'所属科室','type'=>'select','options'=>'lessons'),
					array('name'=>'price','title'=>'门诊价格','type'=>'string'),
					array('name'=>'lineprice','title'=>'在线咨询价格','type'=>'unitstring','unit'=>'次'),
					array('type'=>'checkbox','title'=>'标签','name'=>'label','help'=>'','options'=>'labels'),					
					array('type'=>'checkbox','title'=>'上班时间','name'=>'on_days','help'=>'','options'=>'on_days'),
					array(
									'type'=>'time_box',
									'name'=>'off_timebox',
									'title'=>'免打扰时段',
									'add_tip'=>'添加一个时间段',
									'title1'=>'时间段',
									'field1'=>'times',
									'title2'=>'noshow',
									'title3'=>'noshow',
									'help'=>'免打扰时段(休息时间不可预约及咨询)'
					),
					array('name'=>'is_mingp','title'=>'前端是否显示名片？','type'=>'switch'),
					array('name'=>'address','title'=>'现居住地','type'=>'string'),
					array('name'=>'remark','title'=>'医生简介','type'=>'text'),
					array('name'=>'desc','title'=>'医生详情','type'=>'richtext'),
					array('type'=>'choose','title'=>'绑定会员','name'=>'mid','action'=>'core/member.get_member/','choose_title'=>'选择会员'),
					array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
				)
			),
		)
	);
	if($_SESSION['uniacid']!='windows'){
		unset($htmls['edits'][0]['list'][15]);
	}
	$return['on_days']=array('0'=>'周日','1'=>'周一','2'=>'周二','3'=>'周三','4'=>'周四','5'=>'周五','6'=>'周六');
	$return['sex']=array('1'=>'男','2'=>'女');
	$return['status']=array('0'=>'关闭','1'=>'开启');
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['lesson_id']){
		exi('请选择科室','error');
	}
	//$postdata['time']=ijson_encode($postdata['time']);	
	$data=array_fields(array('is_mingp','lineprice','price','label','paibans','storeid','address','sex','years','name','username','password','mobile','tel','wechat','lessondesc','desc','on_num','on_days','headimg','show','remark','paixu','status','lesson_id','mid'),$postdata);
	$data['years']=strtotime($data['years']);
	$data['paibans']=ijson_encode($data['paibans']);
	$data['off_timebox']=ijson_encode($postdata['off_timebox']);
	$id=intval($postdata['id']);
	if($data['password']){
		$data['password']=base64_encode($data['password']);
	}
	if($id){
		pdo_update('jy_yiliao_worker',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_yiliao_worker',$data);
	}
	exi('操作成功！','','/worker.index/');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的老师！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_yiliao_worker',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}